package com.lei.design.observer;

/**
 * @Author LeiXiaoLei
 * @Date 2022/5/12 21:16
 * @Version 1.0
 */
public class CurrentConditionsDisplay implements DisplayElement, Observer {
    private float temp;
    private float humidity;
    private float pressure;

    public CurrentConditionsDisplay(Subject weatherData) {
        weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.println("=================================");
        System.out.println("当前数据");
        System.out.println(this);
        System.out.println("=================================");
    }


    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temp = temp;
        this.humidity = humidity;
        this.pressure = pressure;
        this.display();
    }

    @Override
    public String toString() {
        return "CurrentConditionsDisplay{" +
                "temp=" + temp +
                ", humidity=" + humidity +
                ", pressure=" + pressure +
                '}';
    }
}
